<style lang="scss" scoped>
	.nav {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		background-color: #f5f5f5;
		z-index: 10;
	}

	.top {
		// padding: 20rpx 0;
		width: 100%;
	}

	.search {
		width: 690rpx;
		height: 68rpx;
		background: #f4f5f7;
		border: 2rpx solid #f5f5f5;
		border-radius: 46rpx;
		margin: 0rpx auto;
		padding: 20rpx;

		.ipt {
			flex: 1;
		}
	}

	.tab {
		
		padding: 0 20rpx;
		height: 100rpx;
		border-bottom: 1px solid #ccc;

		.actived {
			color: #409EFF;
		}
	}

	.lists {
		margin-top: 170rpx;
		
		.list {
			height: 100rpx;
			padding: 20rpx;
		}

		.actived {
			color: #409EFF;
		}
	}
	.footer{
		width:100%;
		background-color: white;
		position: fixed;
		bottom:0;
		left:0;
		border-top: 1px solid #cccccc;
	}
</style>
<template>
	<view class="content">
		<view class="nav">
			<view class="top bgwhite">
				<view class="search align-flex">
					<u-icon name="search" color="#666" size="34"></u-icon>
					<input class="ipt p-left20" type="text" v-model="keywords" @input="search()"
						placeholder="搜索会议室" />
				</view>
			</view>
			<view class="tab align-flex bgwhite">
				<view class="gray m-right20">已选会议室</view>
				<view style="max-width: 550rpx;" class="textColor one" @click="change(index)"> <span v-for="item,index in choose" :key="index"
						class="actived">{{item.name}}<span v-if="index<choose.length-1"
							class="p-left10 p-right10">/</span></span> </view>
			</view>
		</view>
		<view class="lists bgwhite">
			<view class="list between-flex f28" v-for="item,index in list" :key="index"
				@click="chooseItem(item,index)">
				<view class="textColor" :class="item.checked?'actived':''">{{item.name}}</view>
				
				<view v-if="item.checked">
					<u-icon color="#409EFF" name="checkbox-mark"></u-icon>
				</view>
			</view>
			
		</view>
		<view v-if="empty" style="position: fixed;top:40%;left:50%;transform: translateX(-50%);">
			<u-empty text="暂无项目"></u-empty>
		
		</view>
		<view class="space"></view>
		<view class="footer center-flex paddingBottom">
			<view class="lbtn" @click="confirm">确定</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				
				list: [], //显示的列表
				choose:[],
				page: 1,
				
				nomore: false,
				empty: false,
				keywords:'',
				ids:''//需要回显的数据
			}
		},
		onLoad(e) {
			this.reset()
			if(e.hasOwnProperty('ids')){
				this.ids=e.ids
			}
		},
		onReachBottom() {
			if(!this.nomore){
				this.page++
				this.getlist()
			}
		},
		methods: {
			search(){
					this.$u.debounce(this.reset, 500)
				
			},
			reset() {
				this.$showloading()
				this.page = 1
				this.list = []
				this.nomore = false
				this.getlist()
			},
			getlist() {
				
				
				this.$pop.ajaxPost("/bus/busMeetingRoom/page", {
					
					name:this.keywords,
					pageNum: this.page,
					pageSize: 10
				}).then(res => {
					uni.hideLoading()
					var list = res.body.list
					list.forEach(item=>{
						if(item.id==this.ids){
							item.checked=true
						}
					})
					this.list= this.list.concat(list)
								
					if (this.list.length == 0) {
						this.empty = true
					} else {
						this.empty = false
						if (list.length < 10) {
							this.nomore = true
						} else {
							this.nomore = false
						}
					}
					// console.log(this.list)
				})
			},
			//点击最后一级时触发该事件
			confirm() {
				console.log(this.choose)
				var list = this.choose
			
				var name = [],
					value = []
				list.forEach(item => {
					name.push(item.name)
					value.push(item.id)
			
				})
			
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
			
				if (prevPage.$vm.hasOwnProperty('project')) {
			
					prevPage.$vm.meetingRoom = {
						name: name.join('/'),
						value:value.join(','),
						id:value.join(',')
					}
				}
				
				uni.navigateBack({
			
				})
			},
			chooseItem(item, index) {
				
				if(item.checked){
					this.list[index].checked=false
					if(this.choose.indexOf(item)!=-1){
						var index=this.choose.indexOf(item)
						this.choose.splice(index,1)
					}
					
				}else{
					this.list.forEach(item=>{
						item.checked=false
					})
					this.list[index].checked=true
					this.choose=[]
					this.choose.push(item)
				}
				this.$forceUpdate()
			},
			
			

		}
	}
</script>
